<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('标准仓库列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse" >
            <div class="form-group" style="float: right;">
                <label class="checkbox-inline check-box">
                    <input type="text" class="form-control" style="width: 230px" placeholder="按ENTER键执行搜索" id="filter" />
                </label>
            </div>
            <div style="margin-top: 15px" id="dwClassDiv"><span style="font-weight: bold">仓库分类：</span>
                <span class="label" style="cursor: pointer;margin-right: 8px" onclick="themeChange(this)" th:each="item:${labels}" th:text="${item.na}" th:attr="cd=${item.cd}"></span>
            </div>
            <div id="themeItemDiv">
                <div class="themeItem" style="margin-top: 12px;" th:each="label:${labels}" th:attr="cd=${label.cd}">
                    <span style="font-weight: bold;">类别明细：</span>
                    <span class="label" style="cursor: pointer;margin-right: 8px" onclick="themeItemChange(this)" th:each="child:${label.children}" th:text="${child.na}" th:attr="cd=${child.cd}"></span>
                </div>
            </div>
            <form id="formId">
                <input name="cdLabels" type="hidden" id="cdLabels">
                <input name="na" type="hidden" id="na">
            </form>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('etl:dw:edit')}]];
    var removeFlag = [[${@permission.hasPermi('etl:dw:remove')}]];
    var prefix = ctx + "base/etl/dw";
    var themeItemChange = function (ele) {
        var cd = $("#dwClassDiv").find("span.label-info:first").attr("cd");
        $("#themeItemDiv").find("div.themeItem").hide();
        $("#themeItemDiv").find("div.themeItem[cd='"+cd+"']").show();
        if(ele!=null) {
            if($(ele).hasClass("label-info")) {
                $(ele).removeClass("label-info");
            } else {
                $(ele).addClass("label-info");
            }
        }
        refreshTable();
    };
    function themeChange(ele) {
        $("#dwClassDiv").find("span.label").removeClass("label-info");
        $(ele).addClass("label-info");
        themeItemChange(null);
    }
    function refreshTable() {
        debugger;
        var cd = $("#dwClassDiv").find("span.label-info:first").attr("cd");
        var items = $("#themeItemDiv").find("div.themeItem[cd='"+cd+"'] span.label-info");
        var cds = "";
        //                         <span class="label" style="cursor: pointer;margin-right: 8px" onclick="themeItemChange(this)" th:each="child:${label.children}" th:text="${child.na}" th:attr="cd=${child.cd}"></span>
        $.each(items,function (index,item) {
            cds += $(this).attr("cd")+",";
        });
        $("#cdLabels").val(cd.length>0?cds.substring(0,cds.length-1):"");
        $("#na").val($("#filter").val());
        $.table.refresh();
    }
    function createDwTable(idDw) {
        $.ajax({
            url:prefix+"/createTable?idDw="+idDw,
            cache: false,
            type: 'GET',
            dataType: 'json',
            success: function (data) {
                if(data.code=="0") {
                    $.table.refresh();
                    $.modal.alertSuccess("建表成功");
                } else {
                    $.modal.alertError(data.msg);
                }
            }
        });
    };
    function showDetail(id) {
        $.modal.openTab("标准仓库详情",ctx+"base/etl/query/dw/toDetail?idDw="+id);
    }
    $(function() {
        $("#dwClassDiv").find("span.label:first").addClass("label-info");
        themeItemChange();
        var options = {
            url: prefix + "/list2",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "标准仓库",
            columns: [{
                checkbox: true
            },
                {
                    field: 'idDw',
                    title: '',
                    visible: false
                },
                {
                    field: 'cdTb',
                    title: '表名'
                },
                {
                    field: 'na',
                    title: '表描述'
                },
                {
                    field: 'fgTbCre',
                    title: '建表标志',
                    formatter: function(value, row, index) {
                        if(row.fgTbCre==1) {
                            return "已建表";
                        } else {
                            return "未创建";
                        }
                    }

                },
                {
                    field: 'euExecType',
                    title: '执行类型',
                    formatter: function(value, row, index) {
                        if(row.euExecType=="all") {
                            return "全量";
                        } else if(row.euExecType=="date") {
                            return "日期";
                        } else {
                            return "未分类";
                        }
                    }
                },
                {
                    field: 'fgAct',
                    title: '启用标志'
                },
                {
                    field: 'dtSysCre',
                    title: '创建时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="showDetail(\'' + row.idDw + '\')"><i class="fa fa-edit"></i>详情</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
        $("#filter").bind('keyup',function (event) {
            if(event.keyCode=="13") {
                refreshTable();
            }
        });
    });
</script>
</body>
</html>